//
//  Timeline_mvp_tableTableViewController.m
//  MVC|MVP|MVVM
//
//  Created by Guo Rui on 2017/11/14.
//  Copyright © 2017年 GR Harry. All rights reserved.
//

#import "Timeline_mvp_tableTableViewController.h"
#import "TimelineCollectionPresenter.h"
#import "MVP_TableViewCell.h"

@interface Timeline_mvp_tableTableViewController ()<UITableViewDataSource, UITableViewDelegate>
@property (strong, nonatomic) TimelineCollectionPresenter *presenter;
@property (weak, nonatomic) IBOutlet UITableView *tableView;
@end

@implementation Timeline_mvp_tableTableViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    self.presenter = [[TimelineCollectionPresenter alloc] init];
    self.presenter.vc = self;
    
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    
//    self.tableView.contentInset = UIEdgeInsetsMake(200, 0, 0, 0);
    
    [self.presenter loadData];
    
    [self.tableView registerNib:[UINib nibWithNibName:NSStringFromClass([MVP_TableViewCell class]) bundle:nil] forCellReuseIdentifier:@"ID"];
    
//    if (@available(iOS 11.0, *)) {
//        self.tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
//    }
}

#pragma mark - UITableViewDelegate & UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [self.presenter numberOfItems];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    MVP_TableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ID" forIndexPath:indexPath];
    [self.presenter presenterCell:cell atIndex:indexPath.row];
    
    return cell;
}

#pragma mark - TimelineCollectionViewProtocol
- (void)reloadData
{
    [self.tableView reloadData];
}

@end
